package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public boolean save(User user) {
        return userDao.save(user);
    }

    @Override
    public boolean update(User user) {
        return userDao.update(user);
    }

    @Override
    public boolean delete(Integer id) {
        return userDao.delete(id);
    }

    @Override
    public User getById(Integer id) {
        return userDao.getById(id);
    }

    @Override
    public PageInfo<User> getAll(Integer page,Integer size) {
        PageHelper.startPage(page,size);
        List<User> all = userDao.getAll();
        PageInfo<User> pageInfo = new PageInfo<>(all);
        return pageInfo;
    }

    @Override
    public User login(String username, String password) {
        return userDao.getByUsernameAndPassword(username,password);
    }
}
